package xj.meta;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class StereotypeManager {

  public static StereotypeManager getInstance() {
    if (theInstance == null) {
      theInstance = new StereotypeManager();
    }
    return theInstance;
  }

  public Set<String> getAvailableStereotypes(String name) {
    if (name != null) {
      return availableStereotypes.get(name);
    }
    return null;
  }

  public void addAvailableStereotype(String name, String stereotype) {
    if (name != null && stereotype != null) {
      Set<String> set = availableStereotypes.get(name);
      if (set != null) {
	set.add(stereotype);
      } else {
	set = new HashSet<String>();
	set.add(stereotype);
	availableStereotypes.put(name, set);
      }
    }
  }

  public void addAvailableStereotypes(String name, Set<String> stereotypes) {
    if (name != null && stereotypes != null && !stereotypes.isEmpty()) {
      Set<String> set = availableStereotypes.get(name);
      if (set != null) {
	set.addAll(stereotypes);
      } else {
	set = new HashSet<String>();
	set.addAll(stereotypes);
	availableStereotypes.put(name, set);
      }
    }
  }

  public Set<Stereotype> getStereotypes() {
    return stereotypes;
  }

  public void setStereotypes(Set<Stereotype> st) {
    stereotypes.clear();
    if (st != null) {
      stereotypes.addAll(st);
    }
  }

  public void addStereotype(Stereotype s) {
    if (s != null) {
      stereotypes.add(s);
    }
  }

  public void removeStereotype(Stereotype s) {
    if (s != null) {
      stereotypes.remove(s);
    }
  }

  public boolean hasStereotype(Stereotype s) {
    if (s != null) {
      return stereotypes.contains(s);
    }
    return false;
  }

  protected StereotypeManager() {
  }

  protected static StereotypeManager theInstance = null;

  protected Map<String, Set<String>> availableStereotypes = new HashMap();

  protected Set<Stereotype> stereotypes = new HashSet<Stereotype>();

}
